package Entities; //done

import Client.ConnectionToServer;

/**
 * This class controls Product Type details and functions. 
 * @author ameer
 * @author waleed
 * @author bshara
 * @author kamil 
 */
public class Type{
	
	/** Type ID */
	private int TypeID;
	
	/** Type Name */
	private String TypeName;
	
	/**
	 * Default constructor
	 */
	public Type(){
		this.TypeID = 0;
		this.TypeName = null;
	}
	
	/**
	 * @param TypeID type ID
	 * @param TypeName type Name
	 */
	public Type(int TypeID, String TypeName) {
		super();
		this.TypeID = TypeID;
		this.TypeName = TypeName;
	}
	
	/**
	 * @return the type ID
	 */
	public int getTypeID() {
		return TypeID;
	}
	/**
	 * @param TypeID the type ID to set
	 */
	public void setTypeID(int TypeID) {
		this.TypeID = TypeID;
	}
	/**
	 * @return the type Name
	 */
	public String getTypeName() {
		return TypeName;
	}
	/**
	 * @param TypeName the type Name to set
	 */
	public void setTypeName(String TypeName) {
		this.TypeName = TypeName;
	}
	
	/**
	 * This function adds a new Type to DB
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean addType() {		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.addType(TypeID, TypeName);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function removes a type from DB 
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean removeType() {		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.removeType(TypeID);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}	
	
	/**
	 * This function updates a type on DB
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean updateType() {		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.updateType(TypeID, TypeName);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function adds a product to type 
	 * @param ProdID the product ID to add
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean addProductToType(long ProdID){		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.addProductToType(TypeID, ProdID);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}
	
	/**
	 * This function remove a product from type  
	 * @param ProdID the product ID to remove
	 * @return true on success , false on fail
	 * @throws ClientNotInitializesException
	 */
	public boolean removeProductFromType(long ProdID) {		
		ConnectionToServer connectiontoserver = new ConnectionToServer();
		try{
			Object ServerMessage = connectiontoserver.removeProductFromType(TypeID, ProdID);
			if (ServerMessage == null)
				return false;
			if (ServerMessage.equals("OK"))
				return true;
			return false;
		}
		catch(Exception e){
			return false;
		}				
	}	
}
